import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.UUID;

public class Ticket implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    private final String ticketId; // 电子票唯一标识
    private String filmTitle;
    private String screenroom;
    private LocalDateTime startTime;
    private int row; // 座位行
    private int column; // 座位列
    private double price;
    private boolean isActive; // 是否有效（未退票）

    public Ticket(String filmTitle, String screenroom, LocalDateTime startTime, int row, int column, double price) {
        this.ticketId = UUID.randomUUID().toString(); // 生成唯一ID
        this.filmTitle = filmTitle;
        this.screenroom = screenroom;
        this.startTime = startTime;
        this.row = row;
        this.column = column;
        this.price = price;
        this.isActive = true;
    }

    // 获取电子票信息
    public String getTicketInfo() {
        return String.format("电子票ID: %s\n电影: %s\n放映厅: %s\n时间: %s\n座位: 行%d 列%d\n价格: %.2f\n状态: %s",
                ticketId, filmTitle, screenroom, startTime, row, column, price, isActive ? "有效" : "已退票");
    }

    // 退票时调用
    public void invalidate() {
        this.isActive = false;
    }

    // getter
    public String getTicketId() { return ticketId; }
    public boolean isActive() { return isActive; }
    public int getRow() { return row; }
    public int getColumn() { return column; }
    public LocalDateTime getStartTime() { return startTime; }
    public String getScreenRoom(){
        return this.screenroom;
    }
    public String getFilmTitle() {
        return filmTitle;
    }
}